#!/bin/bash

BUILD_ID=DONTKILLME
project_name="league";
log_path=/var/log/webapps/${project_name}/${project_name}-all.logback 

function showpid () {
    echo "`jps -l|grep ${project_name}|awk '{print $1}'`"
}

function stop () {
    if [[ -z "$(showpid)" ]]; then
        echo "${project_name}服务未启动，即将启动。"
        return 0;
    fi
    kill $(showpid)
    while [ true ]; do
        sleep 1s
        if [[ -z "$(showpid)" ]]; then
            echo "${project_name}服务已停止"
            break;
        else
            echo "[$(showpid)]等待进程停止..."
        fi
    done
}


function run () {
    echo "${project_name}启动中，请查看日志：${log_path}"
    nohup java -jar -server -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:+PrintAdaptiveSizePolicy -XX:+UseFastAccessorMethods -XX:+TieredCompilation \
    -XX:+ExplicitGCInvokesConcurrent -Dnacos.config.namespace=test -Dnacos.config.server=172.19.238.14:8848 -Dproject.name="${project_name}" \
    -Dfile.encoding=utf-8 -Dspring.profiles.active=test -Ddruid.mysql.usePingMethod=false \
    ${WORKSPACE}/${project_name}-assemble/target/${project_name}-1.0.jar >> /var/log/webapps/${project_name}/standard.out 2>&1 &
}

stop && run